package com.lujieni.netty.selfaggrement;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.channel.embedded.EmbeddedChannel;
import io.netty.handler.codec.LengthFieldBasedFrameDecoder;
import io.netty.handler.logging.LoggingHandler;

import java.util.ArrayList;
import java.util.List;

public class TestSelfAggrement {

    public static void main(String[] args) throws Exception {


        EmbeddedChannel embeddedChannel = new EmbeddedChannel(new LoggingHandler(), new LengthFieldBasedFrameDecoder(1024, 4, 4, 0, 0), new LujieniCodec());


        List<Object> out = new ArrayList<>();
        new LujieniCodec().encode(null, new Message("lujieni", 32), out);

        ByteBuf buffer = (ByteBuf)out.get(0);
        ByteBuf b1 = buffer.slice(0, 50);
        ByteBuf b2 = buffer.slice(50, buffer.readableBytes() - 50);
        b1.retain();
        embeddedChannel.writeInbound(b1);
        embeddedChannel.writeInbound(b2);

       // embeddedChannel.writeInbound(buffer);

    }

    private static void sendMsgToClient(EmbeddedChannel embeddedChannel) {
        // mock sending message to client
        embeddedChannel.writeOutbound(new Message("lujieni", 32));
    }

}
